﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CocisModel;
using CocisDAL;
using System.Data;

namespace CocisWeb
{
    public partial class Index : System.Web.UI.Page
    {
        public MakeMD5String md5 = new MakeMD5String();
        public LogsDAL logs = new LogsDAL();
        public StaffDAL staffInfo = new StaffDAL();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.TextBoxUserName.Focus();
            }
        }

       
        protected void ImageButtonLogin_Click(object sender, ImageClickEventArgs e)
        {
           
            string LoginName = this.TextBoxUserName.Text;
            string pwd = this.TextBoxPassWord.Text;
            string paswd = md5.StringToMD5(pwd);
            
            UserInfo userInfo = staffInfo.GetUserByNamePwd(LoginName, paswd);
            if (userInfo != null)
            {
                Session["userInfo"] = userInfo;

                //获取IP地址
                string ip = Request.UserHostAddress.ToString();
                int temp = logs.AddNewLogsInfo("system login", userInfo.UserName, ip);

                Response.Redirect("MainFrame.aspx");


            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "b", "<script language=javascript>alert('User name or password is not correct, please try again！')</script>");
              
            }


        }
        private int ConvertInt(string orinString)
        {
            int ret = 0;
            if (!string.IsNullOrEmpty(orinString.Trim()))
            {
                int.TryParse(orinString, out ret);
            }
            return ret;
        }
        private decimal ConvertDec(string orinString)
        {
            decimal ret = 0;
            if (!string.IsNullOrEmpty(orinString.Trim()))
            {
                decimal.TryParse(orinString, out ret);
            }
            return ret;
        }

    }
}
